﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Entangle
{
    public sealed class MessageType
    {
        // ===Tech/Server===
        public const string PUBLIC_KEY_SUBMIT =         "ENTANGLEMENT.TECHREQ.PUBKEYSUBMIT";
        public const string PARTNER_PUBLIC_KEY =        "ENTANGLEMENT.TECHREQ.PUBLICKEY";
        public const string PARTNER_ADDRES =            "ENTANGLEMENT.TECHREQ.PARTNERADDR";

        public const string PARTNER_KEY_FROM_SERV =     "ENTANGLEMENTPHP.TECHRESP.PARTNERKEY";
        public const string MESSAGE_QUEUED_ON_SERVER =  "ENTANGLEMENTPHP.TECHRESP.MESSAGEQUEUED";
        public const string ENTANGLED =                 "ENTANGLEMENTPHP.TECHRESP.ENTANGLED";
        public const string ALREADY_SYNCHED =           "ENTANGLEMENTPHP.TECHRESP.USERALREADYSYNCHED";
        public const string ENTANGLEMENT_FULL =         "ENTANGLEMENTPHP.TECHRESP.ENTFULL";
        public const string ARGUMENT_NULL =             "ENTANGLEMENTPHP.TECHRESP.ARGUMENTNULL";
        public const string PARTNER_NOT_SYNCHED =       "ENTANGLEMENTPHP.TECHRESP.PARTNERNOTSYNCHED";

         public const string SERV_DATA_CORRUPTED =      "ENTANGLEMENTPHP.ERROR.DATACORRUPTED";
         public const string SERV_TECH_ERROR =          "ENTANGLEMENTPHP.ERROR.TECHNICALERROR";

        // ===Requests===
        public const string PARTNER_ADD_NEW_AES_KEY =   "ENTANGLEMENT.REQUEST.ADDAESKEY";

        // ===Responses===
        public const string AES_KEY_ADDED =     "ENTANGLEMENT.RESPONSE.AESADDED";
        public const string ACKNOWLEDGED =      "ENTANGLEMENT.RESPONSE.ACK";

        public const string UNAUTHORISED =      "ENTANGLEMENT.RESPONSE.UNAUTHORISED";
        public const string MESSAGE_MALFORMED = "ENTANGLEMENT.RESPONSE.MALFORMED";
        public const string ERROR =             "ENTANGLEMENT.RESPONSE.ERR";
        public const string INVALID_DATE =      "ENTANGLEMENT.RESPONSE.MSGDATEINVALID";
        public const string UNKNOWN_TYPE =      "ENTANGLEMENT.RESPONSE.UNKNOWNTYPE";


        // ===Notifications===
        public const string STATUS_CHANGED = "ENTANGLEMENT.NOTIFY.STATUSCHANGED";

        public enum EncryptionType
        {
            RSA,
            AES,
            None
        }

        public static bool RequiresSignature(string type)
        {
            // Whitelist
            switch (type)
            {
                case PUBLIC_KEY_SUBMIT:
                    return false; // Doesn't require signature, as cannot be verified either way.
                case UNAUTHORISED:
                    return false; // Doesn't require signature, as doesn't contain any sensitive data.
                default:
                    return true;
            }
        }

        public static EncryptionType PayloadEncryptionType(string type)
        {
            //Whitelist for RSA, default AES.
            switch (type)
            {
                case PARTNER_ADD_NEW_AES_KEY:
                    return EncryptionType.RSA;
                case UNAUTHORISED:
                    return EncryptionType.None;
                case PARTNER_PUBLIC_KEY:
                    return EncryptionType.None;
                default:
                    return EncryptionType.AES;
            }
        }
    }
}
